import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';

import 'package:get/get.dart';

import '../../../style/app_colors.dart';
import '../../../style/widget_style.dart';
import '../../../utils/CommonUtil.dart';
import '../../../widgets/AppHeader.dart';
import '../controllers/forgot_passwd_controller.dart';

class ForgotPasswdView extends GetView<ForgotPasswdController> {
  ForgotPasswdView({super.key});
  final GlobalKey _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SingleChildScrollView(
          controller: controller.scrollController.value,
          child: Stack(
            children: [
              Container(
                child: SvgPicture.asset(
                  "assets/images/header_part_bg.svg",
                  width: Get.width,
                ),
              ),
              AppHeader.obtainHeaderWithoutTitleAndRightPart(),
              Container(
                padding: EdgeInsets.all(15.w),
                width: Get.width,
                margin: EdgeInsets.only(top: 145.h),
                child: Column(
                  children: [
                    Row(
                      children: [
                        Text("忘记密码",style: AppStyleThemeData.BIG_TITLE)
                      ],
                    ),
                    SizedBox(height: 45.h,),
                    Obx(()=> Container(
                      child: Form(
                        key: _formKey,
                        child: Column(
                          children: [
                            Container(
                                child: TextFormField(
                                    decoration: InputDecoration(
                                        labelText: '请输入手机号/邮箱',
                                        labelStyle: AppStyleThemeData.LABEL_TEXT_STYLE,
                                        suffixIcon: controller.suffixIconsVisible.value ? Transform.scale(
                                          scale: 0.5, // 调整缩放比例
                                          child: InkWell(
                                            onTap: () {
                                              /*  phoneFocusNode.requestFocus();
                                      validateFocusNode.unfocus();*/
                                              controller.accountController.value.text = '';
                                              controller.setSuffixIconsVisible(false);
                                            },
                                            child: Image.asset('assets/images/ic_clear.webp'),
                                          ),
                                        ): SizedBox(),
                                        // 关键配置：自定义边框样式
                                        border: const UnderlineInputBorder(
                                          borderSide: BorderSide(color: AppColors.input_bottom_line_color), // 默认状态边框颜色
                                        ),
                                        enabledBorder: const UnderlineInputBorder(
                                          borderSide: BorderSide(color: AppColors.input_bottom_line_color), // 默认状态边框颜色
                                        ),
                                        focusedBorder: const UnderlineInputBorder(
                                          borderSide: BorderSide(color: Colors.blue), // 聚焦状态边框颜色
                                        ),
                                        errorBorder: const UnderlineInputBorder(
                                          borderSide: BorderSide(color: Colors.red), // 错误状态边框颜色
                                        ),
                                        focusedErrorBorder: const UnderlineInputBorder(
                                          borderSide: BorderSide(color: Colors.red), // 聚焦+错误状态边框颜色
                                        ),
                                        contentPadding: const EdgeInsets.fromLTRB(16, 20, 16, 14),
                                        // 可选：添加浮动标签动画间距调整
                                        floatingLabelAlignment: FloatingLabelAlignment.start

                                    ),
                                    controller: controller.accountController.value,
                                    onChanged: (v) {
                                      controller.onTextFieldChange(v);
                                    },
                                    validator: (v) {
                                      if(!CommonUtil.isEmail(v!) &&  !CommonUtil.isChinaPhoneLegal(v!)) {
                                        return '请输入正确的手机号或邮箱';
                                      }
                                      return null;
                                    }
                                )
                            ),
                            SizedBox(height: 30.h),
                            Container(
                                child: TextFormField(
                                  keyboardType: TextInputType.text,
                                  controller: controller.passwordCodeController.value,
                                  obscureText: !controller.pwVisible.value, //This will obscure text dynamically
                                  decoration: InputDecoration(
                                    //labelText: label,
                                      labelText: '输入新密码',
                                      labelStyle: AppStyleThemeData.LABEL_TEXT_STYLE,
                                      //下面是重点
                                      suffixIcon: IconButton(
                                          icon: Icon(
                                            //根据passwordVisible状态显示不同的图标
                                            controller.pwVisible.value ? Icons.visibility : Icons.visibility_off,color: AppColors.disable_btn_bg_color,),
                                          onPressed: () {
                                            //更新状态控制密码显示或隐藏
                                            controller.pwVisible.value = ! controller.pwVisible.value;
                                          }),
                                      // 关键配置：自定义边框样式
                                      border: const UnderlineInputBorder(
                                        borderSide: BorderSide(color: AppColors.input_bottom_line_color), // 默认状态边框颜色
                                      ),
                                      enabledBorder: const UnderlineInputBorder(
                                        borderSide: BorderSide(color: AppColors.input_bottom_line_color), // 默认状态边框颜色
                                      ),
                                      focusedBorder: const UnderlineInputBorder(
                                        borderSide: BorderSide(color: Colors.blue), // 聚焦状态边框颜色
                                      ),
                                      errorBorder: const UnderlineInputBorder(
                                        borderSide: BorderSide(color: Colors.red), // 错误状态边框颜色
                                      ),
                                      focusedErrorBorder: const UnderlineInputBorder(
                                        borderSide: BorderSide(color: Colors.red), // 聚焦+错误状态边框颜色
                                      ),
                                      contentPadding: const EdgeInsets.fromLTRB(16, 20, 16, 14),
                                      // 可选：添加浮动标签动画间距调整
                                      floatingLabelAlignment: FloatingLabelAlignment.start

                                  ),
                                  validator: (v) {
                                    return CommonUtil.confirmValidatePassword(v!,controller.rePasswordCodeController.value.text);
                                  },
                                  onChanged: (v) {
                                    controller.onPwFieldChange(v);
                                  },

                                )
                            ),
                            SizedBox(height: 17.h),
                            Container(
                                child: TextFormField(
                                  keyboardType: TextInputType.text,
                                  controller: controller.rePasswordCodeController.value,
                                  obscureText: !controller.rePwVisible.value, //This will obscure text dynamically
                                  decoration: InputDecoration(
                                    //labelText: label,
                                      labelText: '请再次输入新密码',
                                      labelStyle: AppStyleThemeData.LABEL_TEXT_STYLE,
                                      //下面是重点
                                      suffixIcon: IconButton(
                                          icon: Icon(
                                            //根据passwordVisible状态显示不同的图标
                                            controller.rePwVisible.value ? Icons.visibility : Icons.visibility_off,color: AppColors.disable_btn_bg_color,),
                                          onPressed: () {
                                            //更新状态控制密码显示或隐藏
                                            controller.rePwVisible.value = ! controller.rePwVisible.value;
                                          }),
                                      // 关键配置：自定义边框样式
                                      border: const UnderlineInputBorder(
                                        borderSide: BorderSide(color: AppColors.input_bottom_line_color), // 默认状态边框颜色
                                      ),
                                      enabledBorder: const UnderlineInputBorder(
                                        borderSide: BorderSide(color: AppColors.input_bottom_line_color), // 默认状态边框颜色
                                      ),
                                      focusedBorder: const UnderlineInputBorder(
                                        borderSide: BorderSide(color: Colors.blue), // 聚焦状态边框颜色
                                      ),
                                      errorBorder: const UnderlineInputBorder(
                                        borderSide: BorderSide(color: Colors.red), // 错误状态边框颜色
                                      ),
                                      focusedErrorBorder: const UnderlineInputBorder(
                                        borderSide: BorderSide(color: Colors.red), // 聚焦+错误状态边框颜色
                                      ),
                                      contentPadding: const EdgeInsets.fromLTRB(16, 20, 16, 14),
                                      // 可选：添加浮动标签动画间距调整
                                      floatingLabelAlignment: FloatingLabelAlignment.start

                                  ),
                                  validator: (v) {
                                    return CommonUtil.confirmValidatePassword(v!,controller.passwordCodeController.value.text);
                                  },
                                  onChanged: (v) {
                                    controller.onPwFieldChange(v);
                                  },

                                )
                            ),
                            Container(
                              margin:  EdgeInsets.only(top: 40.h),
                              width: 594.w,
                              height: 50.h,
                              child: ElevatedButton(
                                  onPressed: controller.isSubmitBtnEnable.value == false ? null: () {
                                    if ((_formKey.currentState as FormState).validate()) {
                                         controller.checkValidateCode();
                                    }
                                  },
                                  child: const Text("下一步")
                              ),
                            )
                          ],
                        ),
                      ),
                    ))
                  ],
                ),
              )
            ],
          ),
        )
    );
  }
}
